package cmd

import (
	"context"
	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/net/ghttp"
	"github.com/gogf/gf/v2/os/gcmd"
	"ruoyi-vue-pro-go/internal/controller/auth"
	"ruoyi-vue-pro-go/internal/controller/dept"
	"ruoyi-vue-pro-go/internal/controller/dict"
	"ruoyi-vue-pro-go/internal/controller/dicttype"
	"ruoyi-vue-pro-go/internal/controller/infra"
	"ruoyi-vue-pro-go/internal/controller/menu"
	"ruoyi-vue-pro-go/internal/controller/notifymessage"
	"ruoyi-vue-pro-go/internal/controller/post"
	"ruoyi-vue-pro-go/internal/controller/role"
	"ruoyi-vue-pro-go/internal/controller/rolemenu"
	"ruoyi-vue-pro-go/internal/controller/tenant"
	"ruoyi-vue-pro-go/internal/controller/tenantpackage"
	"ruoyi-vue-pro-go/internal/controller/user"
	"ruoyi-vue-pro-go/internal/controller/userrole"
	"ruoyi-vue-pro-go/internal/middleware"
)

var (
	Main = gcmd.Command{
		Name:  "main",
		Usage: "main",
		Brief: "start http server",
		Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
			s := g.Server()
			s.Group("/", func(group *ghttp.RouterGroup) {
				group.Middleware(ghttp.MiddlewareHandlerResponse, middleware.MiddlewareCORS, middleware.MiddlewareErrorHandler, middleware.MiddlewareAuth, middleware.MiddlewareHasPermission)
				//group.Middleware(ghttp.MiddlewareHandlerResponse, middleware.MiddlewareCORS, middleware.MiddlewareErrorHandler)
				group.Bind(
					user.NewV1(),
					dict.NewV1(),
					tenant.NewV1(),
					auth.NewV1(),
					tenantpackage.NewV1(),
					notifymessage.NewV1(),
					dept.NewV1(),
					role.NewV1(),
					rolemenu.NewV1(),
					menu.NewV1(),
					dicttype.NewV1(),
					post.NewV1(),
					userrole.NewV1(),
					infra.NewV1(),
				)
			})
			s.Run()
			return nil
		},
	}
)
